﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EthernetTools.Utils;

namespace EthernetTools.UI
{
    public partial class TabAbsRawSend : UserControl
    {
        public TabAbsRawSend()
        {
            InitializeComponent();
        }
        
        private void button_send_Click(object sender, EventArgs e)
        {
            button_preview_Click(null, null);

            byte[] packet = Utils.ByteUtils.ParseBytes(textBox_parsed_view.Text);

            if (packet != null)
            {
                if (!MainWindow.Instance.RawEtherInstance.DoWrite(packet))
                {
                    MainWindow.LogWriteLine("Failed!" + Utils.ByteUtils.ByteArrToString(packet), Options.Global.LogLevel.Error);
                }
            }
        }

        private void button_generate_Click(object sender, EventArgs e)
        {
            textBox_raw_byte.Text += ByteUtils.ByteArrToString(new byte[(int)numericUpDown_bytesCount.Value]);
            button_preview_Click(null, null);
        }

        private void button_preview_Click(object sender, EventArgs e)
        {
            textBox_parsed_view.Text = Utils.ByteUtils.ByteArrToString(Utils.ByteUtils.ParseBytes(textBox_raw_byte.Text));
        }
    }
}
